package com.example.controller.seller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.dto.CouponFormDTO;
import com.example.dto.CouponIssueFormDTO;
import com.example.entity.Coupon;
import com.example.service.CouponService;
import com.example.service.StoreService;
import com.example.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "店铺端,优惠券接口")
@RequestMapping("/seller/coupon")
public class SellerCouponController {
    /**
     * 优惠券
     */
    @Resource
    private CouponService couponService;

    @Resource
    private StoreService storeService;

    @PutMapping("/{id}/issue")
    @ApiOperation("发布优惠券")
    public Result issueCoupon(@PathVariable("id") Long id, @RequestBody @Validated CouponIssueFormDTO dto) {
        dto.setId(id);
        return couponService.issueCoupon(dto);
    }


    @ApiOperation("新增优惠券")
    @PostMapping
    public Result addCoupon(@RequestBody @Validated CouponFormDTO dto){
       return  couponService.addCoupon(dto);
    }


    @ApiOperation("分页查询优惠券")
    @GetMapping("/page")
    public Result<IPage<Coupon>> queryPage(Integer pageNum,
                                           Integer pageSize,
                                           Long storeId,
                                           @RequestParam(required = false) Integer couponCategory,
                                           @RequestParam(required = false) Integer couponStatus,
                                           @RequestParam(required = false) String couponName) {

        return couponService.queryMyStorePage(pageNum, pageSize, storeId, couponCategory, couponStatus, couponName);
    }

    @ApiOperation("根据多个id查找")
    @GetMapping("/getListByIds")
    public Result<List<Coupon>> getListByIds(@RequestParam("couponIds") List<Long> couponIds) {

        return Result.ok(couponService.getListByIds(couponIds));
    }


}